/*
 * @Descripttion: 
 * @version: 
 * @Author: zhaomangang
 * @Date: 2024-06-30 15:56:15
 * @LastEditors: zhaomangang
 * @LastEditTime: 2024-06-30 16:09:32
 */
#include "../include/main_widget.h"
MainWidget::MainWidget(QWidget *parent)
    : QWidget(parent)
{
    this->setGeometry(100, 100, 500, 500);
    button_start_ = new QPushButton(this);
    button_start_->setText("start");
    button_start_->show();
    button_stop_ = new QPushButton(this);
    button_stop_->setGeometry(50, 50, 50, 50);
    button_stop_->setText("stop");
    button_stop_->show();
    connect(button_start_, &QPushButton::clicked, this, &MainWidget::slotButtonStartClicked);
    connect(button_stop_, &QPushButton::clicked, this, &MainWidget::slotButtonStopClicked);

    speech_recognition_ = new SpeechRecognition;

    foreach (QString engine, QTextToSpeech::availableEngines())
        qDebug() << engine;
    //audio_capture_ = new AudioCapture;
    //startTimer(5000);
}

MainWidget::~MainWidget() {}


void MainWidget::slotButtonStartClicked()
{
    speech_recognition_->startRecognition();
}

void MainWidget::slotButtonStopClicked()
{
    speech_recognition_->stopRecognition();
    QTextToSpeech *tts = new QTextToSpeech(this);
    tts->setLocale(QLocale::Chinese);//设置语言环境
    tts->setRate(0.0);//设置语速-1.0到1.0
    tts->setPitch(1.0);//设置音高-1.0到1.0
    tts->setVolume(1.0);//设置音量0.0-1.0
    tts->say("设置音量");
    qDebug()<<"say";
}

void MainWidget::timerEvent(QTimerEvent* event)
{
    // QString filepath = "./demo.pcm";//ui->filepath->text();    //获取用户输入地址

    // audio_capture_->stopCapture();

    // Speech my_speech;
    // QString text =my_speech.speechIdentify("./demo.pcm");
    // qDebug()<<text;
    // audio_capture_->startCapture(filepath);  //开始录音
}



